package com.guofen.controller.shlj;

import com.guofen.pojo.ShljAbnormalGarbage;
import com.guofen.pojo.ShljDeodorantSprayingtime;
import com.guofen.service.shlj.DeodorantSprayingtimeService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/shlj/deodorantSprayingtime")
@Controller
@Api(tags = "DeodorantSprayingtimeController", description = "除臭剂喷洒时间表")
public class DeodorantSprayingtimeController {

    @Autowired
    private DeodorantSprayingtimeService service;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm",method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name="time",value="喷洒时间",required=true) @RequestParam String time,
                          @ApiParam(name="signature",value="签字",required=true) @RequestParam String signature){
        if (service.addForm(time,signature))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(service.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="time",value="喷洒时间",required=true) @RequestParam String time,
                         @ApiParam(name="signature",value="签字",required=true) @RequestParam String signature) {
        ShljDeodorantSprayingtime record = new ShljDeodorantSprayingtime();
        record.setId(id);
        record.setTime(time);
        record.setSignature(signature);
        return ResultGenerator.genSuccessResult(service.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(service.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(service.getByTime(pageSize, currentPage, startTime, endTime));
    }

    @ApiOperation("查询记录")
    @RequestMapping(value = "/findForm",method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (service.findForm() != null)
            return ResultGenerator.genSuccessResult(service.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }
}
